package com.test.nnooolwdeaer.activity_fragment_wooden.fragment_wooden;

import android.annotation.SuppressLint;
import android.os.Bundle;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseLoanFragment_wooden;
import com.test.nnooolwdeaer.bean_wooden.StaticVariate_wooden;
import com.test.nnooolwdeaer.bean_wooden.config_info_wooden.AppShowInfo_wooden;
import com.test.nnooolwdeaer.bean_wooden.process_wooden.ProcessInfo_wooden;
import com.test.nnooolwdeaer.bean_wooden.user_info_wooden.LoanApplyDetailInfo_wooden;
import com.test.nnooolwdeaer.constant_wooden.Constant_wooden;
import com.test.nnooolwdeaer.util_wooden.http_wooden.HttpManager_wooden;
import com.test.nnooolwdeaer.view_wooden.module_wooden.ShowWalletAccountListView_Cote_wooden;

public class LoanWaitFragment_wooden extends BaseLoanFragment_wooden {

    private Button refreshStatusBtn_wooden;

    private ImageView imageIv_wooden;
    private TextView titleTv_wooden, textTv_wooden;
    private View tipsView_wooden;

    private TextView loanAmountTv_wooden;
    private TextView loanTermTv_wooden;
    private View showLoanDetailView_wooden, showAccountView_wooden;

    private TextView coteTipTv_wooden;

    private TextView accountTextTv_wooden;
    private TextView accountNameTv_wooden, accountNumTv_wooden;

    private ShowWalletAccountListView_Cote_wooden showAccountView_Cote_wooden;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_loan_wait_wooden, container, false);
        init_wooden(view);
        return view;
    }

    @SuppressLint("SetTextI18n")
    private void init_wooden(View view){

        refreshStatusBtn_wooden = view.findViewById(R.id.fragment_loan_wait_btn_refresh_status);
        imageIv_wooden = view.findViewById(R.id.fragment_loan_wait_iv_image);
        titleTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_title);
        textTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_text);
        loanAmountTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_loan_amount);
        loanTermTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_loan_term);
        showLoanDetailView_wooden = view.findViewById(R.id.fragment_loan_wait_view_show_loan_detail);
        showAccountView_wooden = view.findViewById(R.id.fragment_loan_wait_view_show_account);
        accountTextTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_show_account_text);
        accountNameTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_show_account_name);
        accountNumTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_show_account_num);
        showAccountView_Cote_wooden = view.findViewById(R.id.fragment_loan_wait_view_show_account_cote);
        tipsView_wooden = view.findViewById(R.id.fragment_loan_wait_view_tips);
        coteTipTv_wooden = view.findViewById(R.id.fragment_loan_wait_tv_tip_cote);

        refreshStatusBtn_wooden.setOnClickListener(v -> HttpManager_wooden.getInstance_wooden().requestUserProcess_wooden());

        //放款中
        if (ProcessInfo_wooden.getInstance_wooden().isOrderLoaning_wooden()){
            imageIv_wooden.setBackgroundResource(R.drawable.img_loan_loaning);
            titleTv_wooden.setText(getString(R.string.fragment_loan_loaning_title));
            textTv_wooden.setText(getString(R.string.fragment_loan_loaning_text));
            tipsView_wooden.setVisibility(View.GONE);
            pageTag_wooden = "LOAN_LOANING_FRAGMENT";
        }else {
            imageIv_wooden.setBackgroundResource(R.drawable.img_loan_review);
            titleTv_wooden.setText(getString(R.string.fragment_loan_review_title));
            textTv_wooden.setText(getString(R.string.fragment_loan_review_text));
            tipsView_wooden.setVisibility(View.VISIBLE);
            pageTag_wooden = "LOAN_REVIEWING_FRAGMENT";
        }

        if (StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Cote_wooden)&&(!TextUtils.isEmpty(AppShowInfo_wooden.getInstance().getTransferDelayImportant_wooden()))){
            coteTipTv_wooden.setVisibility(View.VISIBLE);
            coteTipTv_wooden.setText(AppShowInfo_wooden.getInstance().getTransferDelayImportant_wooden());
        }else coteTipTv_wooden.setVisibility(View.GONE);

        switch (StaticVariate_wooden.Select_Country_wooden){
            case Constant_wooden.Country_Cote_wooden:
                showAccountView_wooden.setVisibility(View.GONE);
                showAccountView_Cote_wooden.setVisibility(View.VISIBLE);
                break;
            case Constant_wooden.Country_Ghana_wooden:
                showAccountView_wooden.setVisibility(View.VISIBLE);
                showAccountView_Cote_wooden.setVisibility(View.GONE);
                accountNameTv_wooden.setText("Wallet");
                accountTextTv_wooden.setText("Once the loan is approved, the loan will be transferred to one of your available wallet mobile.");
                break;
            default:
                showAccountView_wooden.setVisibility(View.VISIBLE);
                showAccountView_Cote_wooden.setVisibility(View.GONE);
                accountNameTv_wooden.setText("Account");
                accountTextTv_wooden.setText("Once the loan is approved, the loan will be transferred to one of your available account.");
        }

        HttpManager_wooden.getInstance_wooden().requestLoanApplyDetail_wooden();

    }

    @SuppressLint("SetTextI18n")
    public void onLoanApplyDetailResponse_wooden(){

        if (StaticVariate_wooden.isTestAccount()){
            loanAmountTv_wooden.setText(StaticVariate_wooden.getMoneyUnit_wooden()+" 100000");
            loanTermTv_wooden.setText("365 "+getString(R.string.word_days));
        }else {
            loanAmountTv_wooden.setText(StaticVariate_wooden.getMoneyUnit_wooden()+" "+ LoanApplyDetailInfo_wooden.getInstance_wooden().getAmount_wooden());
            loanTermTv_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getDays_wooden()+" "+getString(R.string.word_days));
        }

        if (StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Ghana_wooden)) accountNumTv_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getWalletMobile_wooden());
        else accountNumTv_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getBankAccount_wooden());

        if (StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Cote_wooden)) HttpManager_wooden.getInstance_wooden().fetchBoundBankAccount_Cote_wooden();

        HttpManager_wooden.getInstance_wooden().fetchStarWindowConfig();

    }

    public void updateWalletAccounts_Cote_wooden(){
        showAccountView_Cote_wooden.updateAccountList_wooden();
    }

}